package com.whiteape.book.model.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.whiteape.book.model.dto.SiteSourceCategoryRuleBean;
import com.whiteape.book.model.dto.SiteSourceChapterInfoBean;
import com.whiteape.book.model.dto.SiteSourceContentInfoBean;
import com.whiteape.book.model.dto.SiteSourceMediaInfoBean;
import com.whiteape.book.model.dto.SiteSourceSearchBean;

import com.whiteape.book.model.dto.SiteSourceBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "SITE_SOURCE_BEAN".
*/
public class SiteSourceBeanDao extends AbstractDao<SiteSourceBean, String> {

    public static final String TABLENAME = "SITE_SOURCE_BEAN";

    /**
     * Properties of entity SiteSourceBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Enabled = new Property(0, Boolean.class, "enabled", false, "ENABLED");
        public final static Property Priority = new Property(1, Integer.class, "priority", false, "PRIORITY");
        public final static Property Creator = new Property(2, String.class, "creator", false, "CREATOR");
        public final static Property SiteName = new Property(3, String.class, "siteName", false, "SITE_NAME");
        public final static Property SiteHostUrl = new Property(4, String.class, "siteHostUrl", true, "SITE_HOST_URL");
        public final static Property SiteIconUrl = new Property(5, String.class, "siteIconUrl", false, "SITE_ICON_URL");
        public final static Property SiteType = new Property(6, int.class, "siteType", false, "SITE_TYPE");
        public final static Property SiteDesc = new Property(7, String.class, "siteDesc", false, "SITE_DESC");
        public final static Property SiteCategory = new Property(8, String.class, "siteCategory", false, "SITE_CATEGORY");
        public final static Property Search = new Property(9, String.class, "search", false, "SEARCH");
        public final static Property MediaInfoDetailRule = new Property(10, String.class, "mediaInfoDetailRule", false, "MEDIA_INFO_DETAIL_RULE");
        public final static Property ChapterInfoRule = new Property(11, String.class, "chapterInfoRule", false, "CHAPTER_INFO_RULE");
        public final static Property ContentInfoRule = new Property(12, String.class, "contentInfoRule", false, "CONTENT_INFO_RULE");
    }

    private final SiteSourceCategoryRuleBean siteCategoryConverter = new SiteSourceCategoryRuleBean();
    private final SiteSourceSearchBean searchConverter = new SiteSourceSearchBean();
    private final SiteSourceMediaInfoBean mediaInfoDetailRuleConverter = new SiteSourceMediaInfoBean();
    private final SiteSourceChapterInfoBean chapterInfoRuleConverter = new SiteSourceChapterInfoBean();
    private final SiteSourceContentInfoBean contentInfoRuleConverter = new SiteSourceContentInfoBean();

    public SiteSourceBeanDao(DaoConfig config) {
        super(config);
    }
    
    public SiteSourceBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"SITE_SOURCE_BEAN\" (" + //
                "\"ENABLED\" INTEGER," + // 0: enabled
                "\"PRIORITY\" INTEGER," + // 1: priority
                "\"CREATOR\" TEXT," + // 2: creator
                "\"SITE_NAME\" TEXT," + // 3: siteName
                "\"SITE_HOST_URL\" TEXT PRIMARY KEY NOT NULL ," + // 4: siteHostUrl
                "\"SITE_ICON_URL\" TEXT," + // 5: siteIconUrl
                "\"SITE_TYPE\" INTEGER NOT NULL ," + // 6: siteType
                "\"SITE_DESC\" TEXT," + // 7: siteDesc
                "\"SITE_CATEGORY\" TEXT," + // 8: siteCategory
                "\"SEARCH\" TEXT," + // 9: search
                "\"MEDIA_INFO_DETAIL_RULE\" TEXT," + // 10: mediaInfoDetailRule
                "\"CHAPTER_INFO_RULE\" TEXT," + // 11: chapterInfoRule
                "\"CONTENT_INFO_RULE\" TEXT);"); // 12: contentInfoRule
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SITE_SOURCE_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SiteSourceBean entity) {
        stmt.clearBindings();
 
        Boolean enabled = entity.getEnabled();
        if (enabled != null) {
            stmt.bindLong(1, enabled ? 1L: 0L);
        }
 
        Integer priority = entity.getPriority();
        if (priority != null) {
            stmt.bindLong(2, priority);
        }
 
        String creator = entity.getCreator();
        if (creator != null) {
            stmt.bindString(3, creator);
        }
 
        String siteName = entity.getSiteName();
        if (siteName != null) {
            stmt.bindString(4, siteName);
        }
 
        String siteHostUrl = entity.getSiteHostUrl();
        if (siteHostUrl != null) {
            stmt.bindString(5, siteHostUrl);
        }
 
        String siteIconUrl = entity.getSiteIconUrl();
        if (siteIconUrl != null) {
            stmt.bindString(6, siteIconUrl);
        }
        stmt.bindLong(7, entity.getSiteType());
 
        String siteDesc = entity.getSiteDesc();
        if (siteDesc != null) {
            stmt.bindString(8, siteDesc);
        }
 
        SiteSourceCategoryRuleBean siteCategory = entity.getSiteCategory();
        if (siteCategory != null) {
            stmt.bindString(9, siteCategoryConverter.convertToDatabaseValue(siteCategory));
        }
 
        SiteSourceSearchBean search = entity.getSearch();
        if (search != null) {
            stmt.bindString(10, searchConverter.convertToDatabaseValue(search));
        }
 
        SiteSourceMediaInfoBean mediaInfoDetailRule = entity.getMediaInfoDetailRule();
        if (mediaInfoDetailRule != null) {
            stmt.bindString(11, mediaInfoDetailRuleConverter.convertToDatabaseValue(mediaInfoDetailRule));
        }
 
        SiteSourceChapterInfoBean chapterInfoRule = entity.getChapterInfoRule();
        if (chapterInfoRule != null) {
            stmt.bindString(12, chapterInfoRuleConverter.convertToDatabaseValue(chapterInfoRule));
        }
 
        SiteSourceContentInfoBean contentInfoRule = entity.getContentInfoRule();
        if (contentInfoRule != null) {
            stmt.bindString(13, contentInfoRuleConverter.convertToDatabaseValue(contentInfoRule));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SiteSourceBean entity) {
        stmt.clearBindings();
 
        Boolean enabled = entity.getEnabled();
        if (enabled != null) {
            stmt.bindLong(1, enabled ? 1L: 0L);
        }
 
        Integer priority = entity.getPriority();
        if (priority != null) {
            stmt.bindLong(2, priority);
        }
 
        String creator = entity.getCreator();
        if (creator != null) {
            stmt.bindString(3, creator);
        }
 
        String siteName = entity.getSiteName();
        if (siteName != null) {
            stmt.bindString(4, siteName);
        }
 
        String siteHostUrl = entity.getSiteHostUrl();
        if (siteHostUrl != null) {
            stmt.bindString(5, siteHostUrl);
        }
 
        String siteIconUrl = entity.getSiteIconUrl();
        if (siteIconUrl != null) {
            stmt.bindString(6, siteIconUrl);
        }
        stmt.bindLong(7, entity.getSiteType());
 
        String siteDesc = entity.getSiteDesc();
        if (siteDesc != null) {
            stmt.bindString(8, siteDesc);
        }
 
        SiteSourceCategoryRuleBean siteCategory = entity.getSiteCategory();
        if (siteCategory != null) {
            stmt.bindString(9, siteCategoryConverter.convertToDatabaseValue(siteCategory));
        }
 
        SiteSourceSearchBean search = entity.getSearch();
        if (search != null) {
            stmt.bindString(10, searchConverter.convertToDatabaseValue(search));
        }
 
        SiteSourceMediaInfoBean mediaInfoDetailRule = entity.getMediaInfoDetailRule();
        if (mediaInfoDetailRule != null) {
            stmt.bindString(11, mediaInfoDetailRuleConverter.convertToDatabaseValue(mediaInfoDetailRule));
        }
 
        SiteSourceChapterInfoBean chapterInfoRule = entity.getChapterInfoRule();
        if (chapterInfoRule != null) {
            stmt.bindString(12, chapterInfoRuleConverter.convertToDatabaseValue(chapterInfoRule));
        }
 
        SiteSourceContentInfoBean contentInfoRule = entity.getContentInfoRule();
        if (contentInfoRule != null) {
            stmt.bindString(13, contentInfoRuleConverter.convertToDatabaseValue(contentInfoRule));
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4);
    }    

    @Override
    public SiteSourceBean readEntity(Cursor cursor, int offset) {
        SiteSourceBean entity = new SiteSourceBean( //
            cursor.isNull(offset + 0) ? null : cursor.getShort(offset + 0) != 0, // enabled
            cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // priority
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // creator
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // siteName
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // siteHostUrl
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // siteIconUrl
            cursor.getInt(offset + 6), // siteType
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // siteDesc
            cursor.isNull(offset + 8) ? null : siteCategoryConverter.convertToEntityProperty(cursor.getString(offset + 8)), // siteCategory
            cursor.isNull(offset + 9) ? null : searchConverter.convertToEntityProperty(cursor.getString(offset + 9)), // search
            cursor.isNull(offset + 10) ? null : mediaInfoDetailRuleConverter.convertToEntityProperty(cursor.getString(offset + 10)), // mediaInfoDetailRule
            cursor.isNull(offset + 11) ? null : chapterInfoRuleConverter.convertToEntityProperty(cursor.getString(offset + 11)), // chapterInfoRule
            cursor.isNull(offset + 12) ? null : contentInfoRuleConverter.convertToEntityProperty(cursor.getString(offset + 12)) // contentInfoRule
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SiteSourceBean entity, int offset) {
        entity.setEnabled(cursor.isNull(offset + 0) ? null : cursor.getShort(offset + 0) != 0);
        entity.setPriority(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1));
        entity.setCreator(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setSiteName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setSiteHostUrl(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setSiteIconUrl(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setSiteType(cursor.getInt(offset + 6));
        entity.setSiteDesc(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setSiteCategory(cursor.isNull(offset + 8) ? null : siteCategoryConverter.convertToEntityProperty(cursor.getString(offset + 8)));
        entity.setSearch(cursor.isNull(offset + 9) ? null : searchConverter.convertToEntityProperty(cursor.getString(offset + 9)));
        entity.setMediaInfoDetailRule(cursor.isNull(offset + 10) ? null : mediaInfoDetailRuleConverter.convertToEntityProperty(cursor.getString(offset + 10)));
        entity.setChapterInfoRule(cursor.isNull(offset + 11) ? null : chapterInfoRuleConverter.convertToEntityProperty(cursor.getString(offset + 11)));
        entity.setContentInfoRule(cursor.isNull(offset + 12) ? null : contentInfoRuleConverter.convertToEntityProperty(cursor.getString(offset + 12)));
     }
    
    @Override
    protected final String updateKeyAfterInsert(SiteSourceBean entity, long rowId) {
        return entity.getSiteHostUrl();
    }
    
    @Override
    public String getKey(SiteSourceBean entity) {
        if(entity != null) {
            return entity.getSiteHostUrl();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SiteSourceBean entity) {
        return entity.getSiteHostUrl() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
